import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'

import Home from '@/views/home/index.vue'
import Kind from '@/views/kind/index.vue'
import Cart from '@/views/cart/index.vue'
import User from '@/views/user/index.vue'

const routes = [
  // redirect 路由重定向
  {
    path: '/',
    // 当访问 / 的时候将路径改到 /home
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: Home
  },
  {
    path: '/kind',
    name: 'kind',
    component: Kind
  },
  {
    path: '/cart',
    name: 'cart',
    component: Cart
  },
  {
    path: '/user',
    name: 'user',
    component: User
  },
  {
    path: '/login',
    name: 'login',
    meta: {
      // 配置路由的元信息
      hidden: true
    },
    component: ()=> import('../views/login/index.vue')
  },{
    path: '/register',
    name: 'register',
    meta: {
      // 配置路由的元信息
      hidden: true
    },
    component: ()=> import('../views/register/index.vue'),
    // 路由重定向，默认打开第一个注册页面
    redirect: '/register/step1',
    children: [
      {
        path: 'step1',
        name: 'step1',
        component: ()=> import('../views/register/step1.vue'),
      },
      {
        path: 'step2',
        name: 'step2',
        component: ()=> import('../views/register/step2.vue'),
      },
      {
        path: 'step3',
        name: 'step3',
        component: ()=> import('../views/register/step3.vue'),
      }
    ]
  },{
    // 定义动态路由
    // path: '/detail/:proid',
    path: '/detail',
    name: 'detail',
    meta: {
       // 配置路由的元信息
       hidden: true
    },
    component: ()=> import('@/views/detail/index.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes
})

export default router
